class Verify {
  phone(val) {
    return (/^0?(13[0-9]|14[5-9]|15[012356789]|166|17[0-8]|18[0-9]|19[8-9])[0-9]{8}$/.test(val))
  }
}
class Format {
  formatLocation(longitude, latitude) {
    longitude = Number(longitude).toFixed(2)
    latitude = Number(latitude).toFixed(2)

    return {
      longitude: longitude.toString().split('.'),
      latitude: latitude.toString().split('.')
    }
  }
  amount(val) {
    //金额转换 分->元 保留2位小数 并每隔3位用逗号分开 1,234.56
    var str = (val / 100).toFixed(2) + '';
    var intSum = str.substring(0, str.indexOf(".")).replace(/\B(?=(?:\d{3})+$)/g, ','); //取到整数部分
    var dot = str.substring(str.length, str.indexOf(".")) //取到小数部分搜索
    var ret = intSum + dot;
    return ret;
  }
  amountClear(val) { //取消字符串中出现的所有逗号 
    var str = val.replace(/,/g, '') * 100;
    return str;
  }
  date(fmt, date) {
    // 调用：format.date("yyyy-MM-dd hh:mm:ss", startDate)
    var o = {
      "M+": date.getMonth() + 1, //月份   
      "d+": date.getDate(), //日   
      "h+": date.getHours(), //小时   
      "m+": date.getMinutes(), //分   
      "s+": date.getSeconds(), //秒   
      "q+": Math.floor((date.getMonth() + 3) / 3), //季度   
      "S": date.getMilliseconds() //毫秒   
    };
    if (/(y+)/.test(fmt))
      fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
      if (new RegExp("(" + k + ")").test(fmt))
        fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
  }
  seconds(value) {
    if (value == undefined) {
      value = 0;
    }
    var second = parseInt(value); // 秒
    var min = 0; // 分
    var hour = 0; // 小时
    if (second > 60) {
      min = parseInt(second / 60);
      second = parseInt(second % 60);
      if (min > 60) {
        hour = parseInt(min / 60);
        min = parseInt(min % 60);
      }
    }
    var h = hour < 10 ? "0" + parseInt(hour) : parseInt(hour)
    var m = min < 10 ? "0" + parseInt(min) : parseInt(min)
    var s = second < 10 ? "0" + parseInt(second) : parseInt(second)


    var result = "" + h + ":" + m + ":" + s;
    return result;
  }
  watch(value) {
    if (value == undefined) {
      value = 0;
    }
    var millisecond = parseInt(value); // 毫秒
    var second = 0; // 秒
    var min = 0; // 分
    var hour = 0; // 小时
    if (millisecond>99) {
      second = parseInt(millisecond / 100)
      millisecond = parseInt(millisecond % 100);
      if (second > 60) {
        min = parseInt(second / 60);
        second = parseInt(second % 60);
        if (min > 60) {
          hour = parseInt(min / 60);
          min = parseInt(min % 60);
        }
      }
    }
    var h = hour < 10 ? "0" + parseInt(hour) : parseInt(hour)
    var m = min < 10 ? "0" + parseInt(min) : parseInt(min)
    var s = second < 10 ? "0" + parseInt(second) : parseInt(second)
    var ms = millisecond < 10 ? "0" + parseInt(millisecond) : parseInt(millisecond)
    var time = {
      m: m,
      s: s,
      ms: ms
    }
    var result = "" + h + ":" + m + ":" + s+":"+ms;
    return time;
  }
}

class Common {
  clipName(v) {
    var nV = v.match(/\(([^)]*)\)/)
    return nV[1]
  }
}
export {
  Verify,
  Format,
  Common
}